package com.bite.demo;

import com.bite.demo.component.UserComponent;
import com.bite.demo.config.UserConfig;
import com.bite.demo.config.UserInfo;
import com.bite.demo.controller.UController;
import com.bite.demo.controller.UserController;
import com.bite.demo.repo.UserRepository;
import com.bite.demo.service.UserService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;

@ComponentScan("com.bite.demo")
@SpringBootApplication
public class DemoApplication {

	public static void main(String[] args) {
		//Spring上下文
		ApplicationContext context = SpringApplication.run(DemoApplication.class, args);
		//从context中获取bean
		UserController bean = context.getBean(UserController.class);
		bean.doController();

//		UserService userService = context.getBean(UserService.class);
//		userService.doService();
		//根据名称来获取bean
//		UserService userService2 = (UserService)context.getBean("uuuuu");
//		userService2.doService();
//		//根据名称和类型获取bean
//		UserService userService3 = context.getBean("userService", UserService.class);
//		userService3.doService();
//
//		//特殊情况: 如果类名前两位都为大写, bean的名称为类名
//		UController uController = (UController)context.getBean("UController");
//		uController.doController();
//
//		UserRepository userRepository = context.getBean(UserRepository.class);
//		userRepository.doRepository();
//
//		UserComponent userComponent = context.getBean(UserComponent.class);
//		userComponent.doComponent();
//
//		UserConfig userConfig = context.getBean(UserConfig.class);
//		userConfig.doConfig();
//		System.out.println("userConfig:"+userConfig);
//
//		UserConfig userConfig2 = context.getBean(UserConfig.class);
//		System.out.println("userConfig2:"+userConfig2);
//		System.out.println("userConfig == userConfig2: "+ (userConfig == userConfig2));
//
//		//@Bean演示
//		UserInfo userInfo = (UserInfo) context.getBean("userInfo");
//		System.out.println(userInfo);

//		UserInfo userInfo2 = context.getBean("userInfo2", UserInfo.class);
//		System.out.println(userInfo2);
	}

}
